package com.medicine.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * session 过期处理
 * @author jim
 *
 */
public class SystemSessionInterceptor implements HandlerInterceptor {

	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		HttpSession session = request.getSession(true);
		Object obj = session.getAttribute(CommonConstant.LOGIN_USER);
		System.out.println("=====================filfter:"+obj);
		if(null == obj ){
			//System.out.println("==================return url:"+request.getSession().getServletContext().getContextPath());
			response.sendRedirect(request.getSession().getServletContext().getContextPath()+"/page/index.html");
		    return false;
		}
		return true;
	}

}
